﻿<?php

class Urlform extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
		
		$this->load->library('form_validation');
		
		$this->load->model('Suburl_ml');
			
	//	$this->output->enable_profiler(true);
		//$this->form_validation->set_rules('shorturl', 'shorturl','required|min_length[2]|max_length[12]|is_unique[shorturl]');
		$this->form_validation->set_rules('shorturl');
		$this->form_validation->set_rules('purposeUrl', 'purposeUrl','required');	
	}
 public function index($islogin=0)
 {
 	 $accid=1;
	 $memId=1;
	  if ($islogin==1)
	  {
	  	
	  	$this->memberIndexPage($memId);
	  }
	  else
	  {
	  	
	  	$this->customerIndexPage();
	  }

 }
 public function customerIndexPage()	//未登录用户主页
 {
 /*	if ($this->form_validation->run() == FALSE)
 	{
 		$this->load->view('inc/header');
 		$this->load->view('index_v');
 	}
 	else
 	{
 		$this->urlsub();
 		///////////////////////////////////////////////////
 
 	}
 	*/
 	$this->load->view('inc/header');
 	$this->load->view('index_v'); 	
 }
  function memberIndexPage($memId)	//登录用户主页 
 {
 		$domain=$this->Suburl_ml->getOwnDomain($memId);	//获取该用户所拥有的域名
 	//	print_r($domain);
 		$domainHtml = "[";
 		foreach ($domain as $item)
 		{					 			
 				$domainHtml .= "{name:'".$item->userdomain."'},";	
 		}
 		$domainHtml=substr($domainHtml,0,strlen($domainHtml)-1);
 		$domainHtml .= "]";
 		$domainInfo=array("domain"=>$domainHtml);
		$domainInfo=array("domain"=>$domainHtml);
 		$this->load->view('inc/header');
 		$this->load->view('memBackground',$domainInfo);
 		
 	}	
 function memOnwerUrl(){
 	$urlRecord="
 	<div id='historyHeadline'><h3>Link &amp; Bundle History: 1 - 2</h3><div class='resultsHeaderContainer'></div></div>
 	<div id='weeklySparkLines'><div style='display:none;' class='innerWeeklyClickSummaryContainer'><canvas id='sparkline_canvas' width='66' height='20'></canvas></div></div>
 	<div id='results'><p class='bundle_message preview_message'><a href='#' class='close'>x</a><strong>New!</strong>Preview the contents of your links by toggling here</p><ul id='multiline_toggle' class='oneRowSelected'><li><a class='showMoreInfo' type='two_row' href='#'>Two Rows</a></li><li><a class='hideMoreInfo' type='one_row' href='#'>One Row</a></li></ul><div class='detailsControlBox clearfix'>
 	<ul id='history_view_toggle' class='clearfix'><li>View: </li><li><a href='#' class='all inactive'>All</a></li><li><a href='#' class='bundles'>Bundles</a></li></ul><form id='create_bundle' action='/data/create_bundle' method='POST'>
 	<fieldset><input type='hidden' id='create_bundle_hashes' name='hashes' value=''><input type='submit' class='white_button' value='Bundle'><input type='hidden' name='_xsrf' value='ec12d1603d7c4596b4f9c6965343a946'></fieldset></form></div>
 	<div class='resultsBarContainer'><b class='resultsBar1'><input type='checkbox' id='toggle_all'> Clicks </b><b class='resultsBar2'> Links </b><b class='resultsBar3'> Info Plus </b><b class='resultsBar4'> Date </b><b class='resultsBar5'> Options </b></div>
 	
 	";
 	$memId=1;
 	$urlHistory=$this->Suburl_ml->getHistoryShorturl($memId);	//获取该用户所添加的短网址
 	if($urlHistory){
 		foreach ($urlHistory as $item){
 			if($item->nowUrl=="auto"){
 				$shorturl=$item->id;
 			}else{
 				$shorturl=$item->nowUrl;
 			}
 			
 			$urlRecord.="<div class='resultsItemContainer'>
 	<div class='resultsColumn2 resultsColumn'><form class='bundle_cb_form'><fieldset><input type='checkbox' class='item_cb' value='y6Hq1K'></fieldset></form><div class='statsList' style='display: block; '><div class='userStats'><h4><a title='Get Real-time Metrics for this link' type='y6Hq1K' href='/y6Hq1K+'>0</a></h4></div><div class='statsSeparator'>out of</div><div class='globalStats'><a type='xHBe6I' href='/xHBe6I+'>0</a></div></div><div class='hr'><hr></div></div> <div class='resultsColumn4 resultsColumn'>";
 			$urlRecord.="
 			<div class='linkTitleContainer'><h4 class='linkTitle'><img class='historyFavicon' src='/favicon/xHBe6I.png' width='16' height='16' alt='favicon' border='0'><a title='{$item->purposeUrl}' href='http://{$item->useDomain}/urlshort/$shorturl'>{$item->purposeUrl}</a></h4></div><div class='long_url_display_more'><a href='{$item->purposeUrl}' title='{$item->purposeUrl}'>{$item->purposeUrl}</a></div><div class='short_url_display_more'><a href='http://{$item->useDomain}/urlshort/$shorturl' title='http://{$item->useDomain}/urlshort/$shorturl' class='hash'>{$item->useDomain}/urlshort/$shorturl</a><span class='copy_customize flash'><a style='text-indent: 0px; ' class='copy_button' href='#' data-href='http://{$item->useDomain}/urlshort/$shorturl'> - Copy<span class='clippy'></span><div style='position: absolute; left: 0px; top: 0px; width: 37px; height: 28px; z-index: 99; '><embed id='ZeroClipboardMovie_6' src='/s/v404/flash/zeroclipboard/ZeroClipboard.swf' loop='false' menu='false' quality='best' bgcolor='#ffffff' width='37' height='28' name='ZeroClipboardMovie_6' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='id=6&amp;width=37&amp;height=28' wmode='transparent'></div></a></span></div></div><div class='resultsColumn5 resultsColumn'><a href='/y6Hq1K+' title='Real-time stats for bit.ly/y6Hq1K+'>Info Page+</a></div><div class='resultsColumn6 resultsColumn'><div class='dateAndTimeBox'>  41 mins ago</div></div><div class='resultsColumn7 resultsColumn'><div class='optionsDropDownContainer' type='y6Hq1K' alt='http://bit.ly/y6Hq1K'><ul class='toolsDropList'><li class='topLevel'><div class='optionsToolPanel'><b class='topLeft'></b><b class='topRight'></b><span>Options</span></div><ul class='toolsList'><li class='toolsListShare'><a class='optionsShareButton' href='#'>Share</a></li><li class='optionsCopyButtonContainer'><a class='optionsCopyButton' href='#'>Copy</a><div style='position: absolute; left: 0px; top: 0px; z-index: 99; width: 65px; height: 20px; '><embed id='ZeroClipboardMovie_8' src='/s/v404/flash/zeroclipboard/ZeroClipboard.swf' loop='false' menu='false' quality='best' bgcolor='#ffffff' width='60' height='20' name='ZeroClipboardMovie_8' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='id=8&amp;width=60&amp;height=20' wmode='transparent'></div></li><li class='toolsListDelete'><a class='optionsDeleteButton' href='#'>Archive</a></li><li class='editableTitleListItem'><a class='editableTitleButton' href='#'>Edit</a></li></ul></li></ul></div></div><div class='moreInfo row2'><div id='history_preview_xHBe6I' class='link_preview'></div></div><div class='hr'><hr></div>
 			</div> <!-- end .resultsItemContainer -->";
 		}
 	}
/*	$urlRecord.="
 	<div class='linkTitleContainer'><h4 class='linkTitle'><img class='historyFavicon' src='/favicon/xHBe6I.png' width='16' height='16' alt='favicon' border='0'><a title='http://www.anytime-anywhere.info/' href='http://bit.ly/y6Hq1K'>http://www.anytime-anywhere.info/</a></h4></div><div class='long_url_display_more'><a href='http://www.anytime-anywhere.info/' title='http://www.anytime-anywhere.info/'>http://www.anytime-anywhere.info/</a></div><div class='short_url_display_more'><a href='http://bit.ly/y6Hq1K' title='http://bit.ly/y6Hq1K' class='hash'>bit.ly/y6Hq1K</a><span class='copy_customize flash'><a style='text-indent: 0px; ' class='copy_button' href='#' data-href='http://bit.ly/y6Hq1K'> - Copy<span class='clippy'></span><div style='position: absolute; left: 0px; top: 0px; width: 37px; height: 28px; z-index: 99; '><embed id='ZeroClipboardMovie_6' src='/s/v404/flash/zeroclipboard/ZeroClipboard.swf' loop='false' menu='false' quality='best' bgcolor='#ffffff' width='37' height='28' name='ZeroClipboardMovie_6' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='id=6&amp;width=37&amp;height=28' wmode='transparent'></div></a></span></div></div><div class='resultsColumn5 resultsColumn'><a href='/y6Hq1K+' title='Real-time stats for bit.ly/y6Hq1K+'>Info Page+</a></div><div class='resultsColumn6 resultsColumn'><div class='dateAndTimeBox'>  41 mins ago</div></div><div class='resultsColumn7 resultsColumn'><div class='optionsDropDownContainer' type='y6Hq1K' alt='http://bit.ly/y6Hq1K'><ul class='toolsDropList'><li class='topLevel'><div class='optionsToolPanel'><b class='topLeft'></b><b class='topRight'></b><span>Options</span></div><ul class='toolsList'><li class='toolsListShare'><a class='optionsShareButton' href='#'>Share</a></li><li class='optionsCopyButtonContainer'><a class='optionsCopyButton' href='#'>Copy</a><div style='position: absolute; left: 0px; top: 0px; z-index: 99; width: 65px; height: 20px; '><embed id='ZeroClipboardMovie_8' src='/s/v404/flash/zeroclipboard/ZeroClipboard.swf' loop='false' menu='false' quality='best' bgcolor='#ffffff' width='60' height='20' name='ZeroClipboardMovie_8' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='id=8&amp;width=60&amp;height=20' wmode='transparent'></div></li><li class='toolsListDelete'><a class='optionsDeleteButton' href='#'>Archive</a></li><li class='editableTitleListItem'><a class='editableTitleButton' href='#'>Edit</a></li></ul></li></ul></div></div><div class='moreInfo row2'><div id='history_preview_xHBe6I' class='link_preview'></div></div><div class='hr'><hr></div>
 	</div> <!-- end .resultsItemContainer -->
 	<div class='resultsItemContainer lastResultsItemContainer'><div class='resultsColumn2 resultsColumn'><form class='bundle_cb_form'><fieldset><input type='checkbox' class='item_cb' value='yHhcX9'></fieldset></form><div class='statsList' style='display: block; '><div class='userStats'><h4><a title='Get Real-time Metrics for this link' type='yHhcX9' href='/testbaidu+'>0</a></h4></div><div class='statsSeparator'>out of</div><div class='globalStats'><a type='baobao' href='/baobao+'>718</a></div></div><div class='hr'><hr></div></div> <div class='resultsColumn4 resultsColumn'><div class='linkTitleContainer'><h4 class='linkTitle'><img class='historyFavicon' src='/favicon/baobao.png' width='16' height='16' alt='favicon' border='0'><a title='http://www.baidu.com/' href='http://bit.ly/testbaidu'>百度一下，你就知道</a></h4></div><div class='long_url_display_more'><a href='http://www.baidu.com/' title='http://www.baidu.com/'>http://www.baidu.com/</a></div><div class='short_url_display_more'><a href='http://bit.ly/testbaidu' title='http://bit.ly/testbaidu' class='hash'>bit.ly/testbaidu</a><span class='copy_customize flash'><a style='text-indent: 0px; ' class='copy_button' href='#' data-href='http://bit.ly/testbaidu'> - Copy<span class='clippy'></span><div style='position: absolute; left: 0px; top: 0px; width: 37px; height: 28px; z-index: 99; '><embed id='ZeroClipboardMovie_7' src='/s/v404/flash/zeroclipboard/ZeroClipboard.swf' loop='false' menu='false' quality='best' bgcolor='#ffffff' width='37' height='28' name='ZeroClipboardMovie_7' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='id=7&amp;width=37&amp;height=28' wmode='transparent'></div></a></span></div></div><div class='resultsColumn5 resultsColumn'><a href='/testbaidu+' title='Real-time stats for bit.ly/testbaidu+'>testbaidu+</a></div><div class='resultsColumn6 resultsColumn'><div class='dateAndTimeBox'>  1 day ago</div></div><div class='resultsColumn7 resultsColumn'><div class='optionsDropDownContainer' type='yHhcX9' alt='http://bit.ly/testbaidu'><ul class='toolsDropList'><li class='topLevel'><div class='optionsToolPanel'><b class='topLeft'></b><b class='topRight'></b><span>Options</span></div><ul class='toolsList'><li class='toolsListShare'><a class='optionsShareButton' href='#'>Share</a></li><li class='optionsCopyButtonContainer'><a class='optionsCopyButton' href='#'>Copy</a><div style='position: absolute; left: 0px; top: 0px; z-index: 99; width: 65px; height: 20px; '><embed id='ZeroClipboardMovie_9' src='/s/v404/flash/zeroclipboard/ZeroClipboard.swf' loop='false' menu='false' quality='best' bgcolor='#ffffff' width='60' height='20' name='ZeroClipboardMovie_9' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='id=9&amp;width=60&amp;height=20' wmode='transparent'></div></li><li class='toolsListDelete'><a class='optionsDeleteButton' href='#'>Archive</a></li><li class='editableTitleListItem'><a class='editableTitleButton' href='#'>Edit</a></li></ul></li></ul></div></div><div class='moreInfo row2'><div id='history_preview_baobao' class='link_preview'></div></div><div class='hr'><hr></div>
 	</div> <!-- end .resultsItemContainer --><div id='pagination'></div></div> <!-- end #resultsContainer -->
 	";
 	*/
 	echo $urlRecord;
 }
 function memUrlSub(){		//登录用户短地址提交
 	$this->form_validation->set_rules('domain', 'domain','required');	//登录会员才判断所属域名是否提交
 	if ($this->form_validation->run() == FALSE)
 	//if(1==2)
 	{
 		$htmlStr="[{errorinfo:'请输入目的地址',error:'1'}]";
 		echo $htmlStr;
 	//	echo "<li class='linkCapsule_link clearfix' hash='baobao' style='display: block; background-color: rgb(255, 255, 255); '>请输入您要缩短的网址</li>";
 	}else{
 		$shorturl=set_value('shorturl');
 		if(strlen($shorturl)==0 or intval($shorturl)){
 			$shorturl="auto";
 		}
 		$purposeUrl=set_value('purposeUrl') ;
 		if(!stristr($purposeUrl,"http://")){
 			$purposeUrl="http://".$purposeUrl;
 		} 		
	 	$data=array("nowUrl"=>$shorturl,"purposeUrl"=>$purposeUrl,"useDomain"=>set_value('domain'));
	 	$urlid=$this->Suburl_ml->insertUrl($data);	//返回记录id
	 	if($shorturl=="auto"){
	 		$shorturl=$urlid;
	 	}
	 	$u=set_value('domain')."/urlshort/".$shorturl;
	 	$e="http://".set_value('domain')."/urlshort/".$shorturl;
	 	$htmlStr="[{shorturl:'$e',purposeUrl:'$purposeUrl',error:'0'}]";
	 	echo $htmlStr;
 	}
 }
 function urlsub(){	//未登录用户
 	if ($this->form_validation->run() == FALSE)
 	{
 		//$this->load->view('inc/header');
 		//$this->load->view('index_v');
 		echo "<li class='linkCapsule_link clearfix' hash='baobao' style='display: block; background-color: rgb(255, 255, 255); '>请输入您要缩短的网址</li>";
 	}else{
 		$shorturl=set_value('shorturl');
 		if(strlen($shorturl)==0){
 			$shorturl="auto";
 		}
 		$purposeUrl=set_value('purposeUrl') ;
 		if(!stristr($purposeUrl,"http://")){
 			$purposeUrl="http://".$purposeUrl;
 		}
 		$data=array("nowUrl"=>$shorturl,"purposeUrl"=>set_value('purposeUrl'),"useDomain"=>"short.com");
 		$shorturl=$this->Suburl_ml->insertUrlCustorm($data);
 		$u="short.com/".$shorturl;
 		$e="http://short.com/".$shorturl;
 	//	$urldata=array('url'=>$e);
 		$htmlStr="<li class='linkCapsule_link clearfix' hash='baobao' style='display: block; background-color: rgb(255, 255, 255); '><div class='shortened_url clearfix'>";
 		$htmlStr.="<a class='short_url' href='$e' target='_blank'><span class='hash'>$u</span></a><span class='copy_customize flash'>";
 		$htmlStr.="<a href='#' class='customize_button'>Customize</a><span class='copy_separator'> | </span><a href='#' data-href='http://bit.ly/baobao' class='copy_button' style='text-indent: 0px; '>Copy<span class='clippy'></span><div style='position: absolute; left: 0px; top: 0px; width: 37px; height: 28px; z-index: 99; '>";
 		$htmlStr.="<embed id='ZeroClipboardMovie_1' src='".base_url()."public_html/flash/ZeroClipboard.swf' loop='false' menu='false' quality='best' bgcolor='#ffffff' width='37' height='28' name='ZeroClipboardMovie_1' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='id=1&amp;width=37&amp;height=28' wmode='transparent'></div></a></span></div>";
 		$htmlStr.="<a class='realtime_stats' href='http://bit.ly/baobao+' target='_blank'>Info Page+</a>";
 		$htmlStr.="<a class='long_link' href='$purposeUrl' target='_blank' title='$purposeUrl'>$purposeUrl</a></li>";
 		echo $htmlStr;
 	}
 }
  function username_check($str)
 {
  if ($str == 'test')
  {
   $this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
   return FALSE;
  }
  else
  {
   return TRUE;
  }
 }
 
}
?>